package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TourismPact;
import com.ruoyi.system.domain.TourismUser;
import com.ruoyi.system.mapper.TourismPactMapper;
import com.ruoyi.system.mapper.TourismUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TourismCharacteristicMapper;
import com.ruoyi.system.domain.TourismCharacteristic;
import com.ruoyi.system.service.ITourismCharacteristicService;

import javax.annotation.Resource;

/**
 * 特色商品Service业务层处理
 *
 * @author gqd
 * @date 2020-12-25
 */
@Service
public class TourismCharacteristicServiceImpl implements ITourismCharacteristicService
{
    @Autowired
    private TourismCharacteristicMapper tourismCharacteristicMapper;
    @Resource
    private TourismPactMapper tourismPactMapper;
    @Resource
    private TourismUserMapper tourismUserMapper;

    /**
     * 查询特色商品
     *
     * @param id 特色商品ID
     * @return 特色商品
     */
    @Override
    public TourismCharacteristic selectTourismCharacteristicById(Integer id)
    {
        return tourismCharacteristicMapper.selectTourismCharacteristicById(id);
    }

    /**
     * 查询特色商品列表
     *
     * @param tourismCharacteristic 特色商品
     * @return 特色商品
     */
    @Override
    public List<TourismCharacteristic> selectTourismCharacteristicList(TourismCharacteristic tourismCharacteristic)
    {
        return tourismCharacteristicMapper.selectTourismCharacteristicList(tourismCharacteristic);
    }

    /**
     * 新增特色商品
     *
     * @param tourismCharacteristic 特色商品
     * @return 结果
     */
    @Override
    public int insertTourismCharacteristic(TourismCharacteristic tourismCharacteristic)
    {
        tourismCharacteristic.setCreateTime(DateUtils.getNowDate());
        return tourismCharacteristicMapper.insertTourismCharacteristic(tourismCharacteristic);
    }

    /**
     * 修改特色商品
     *
     * @param tourismCharacteristic 特色商品
     * @return 结果
     */
    @Override
    public int updateTourismCharacteristic(TourismCharacteristic tourismCharacteristic)
    {
        tourismCharacteristic.setUpdateTime(DateUtils.getNowDate());
        return tourismCharacteristicMapper.updateTourismCharacteristic(tourismCharacteristic);
    }

    /**
     * 批量删除特色商品
     *
     * @param ids 需要删除的特色商品ID
     * @return 结果
     */
    @Override
    public int deleteTourismCharacteristicByIds(Integer[] ids)
    {
        return tourismCharacteristicMapper.deleteTourismCharacteristicByIds(ids);
    }

    /**
     * 删除特色商品信息
     *
     * @param id 特色商品ID
     * @return 结果
     */
    @Override
    public int deleteTourismCharacteristicById(Integer id)
    {
        return tourismCharacteristicMapper.deleteTourismCharacteristicById(id);
    }

    /**
     * 查询所有的商品
     * @param characteristicName
     * @return
     */
    @Override
    public AjaxResult selectAll(String characteristicName) {
        List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectAll(characteristicName);
        if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
            return AjaxResult.error("暂时还没有商品的信息！");
        }
        return AjaxResult.success(tourismCharacteristics);
    }

    /**
     * 查询农副产品
     * @param characteristicName
     * @return
     */
    @Override
    public AjaxResult selectByStatusOne(String characteristicName) {
        List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusOne(characteristicName);
        if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
            return AjaxResult.error("暂时还没有特色商品的信息！");
        }
        return AjaxResult.success(tourismCharacteristics);
    }

    /**
     * 根据商品id查询商品的详细信息
     * @param id
     * @return
     */
    @Override
    public AjaxResult selectById(Integer id,Integer userId) {
        TourismUser tourismUser = tourismUserMapper.selectByUserId(userId);

        TourismCharacteristic tourismCharacteristic = tourismCharacteristicMapper.selectById(id);
        if(tourismCharacteristic == null){
            return AjaxResult.error("暂时还没有该商品的详细信息！");
        }
        if(tourismUser == null || userId == null){
            tourismCharacteristic.setFlag("0");
        }else{
            TourismPact tourismPact = tourismPactMapper.selectSpotPact4(id,userId);
            if(tourismPact == null){
                tourismCharacteristic.setFlag("0");
            }else {
                tourismCharacteristic.setFlag("1");
            }
        }
        return AjaxResult.success(tourismCharacteristic);
    }

    /**
     * 查询根雕
     * @param characteristicName
     * @return
     */
    @Override
    public AjaxResult selectByStatusTwo(String characteristicName) {
        List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusTwo(characteristicName);
        if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
            return AjaxResult.error("暂时还没有非遗商品的信息！");
        }
        return AjaxResult.success(tourismCharacteristics);
    }

    /**
     * 查询非遗
     * @param characteristicName
     * @return
     */
    @Override
    public AjaxResult selectByStatusThree(String characteristicName) {
        List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusThree(characteristicName);
        if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
            return AjaxResult.error("暂时没有其他商品的信息！");
        }
        return AjaxResult.success(tourismCharacteristics);
    }

    /**
     * 特色商品
     * @param characteristicName
     * @param status
     * @return
     */
    @Override
    public AjaxResult selectCharacteristic(String characteristicName, Integer status) {
        if(status == 0){
            List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectAll(characteristicName);
            if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
                return AjaxResult.error("暂时还没有商品的信息！");
            }
            return AjaxResult.success(tourismCharacteristics);
        }else if(status == 1){
            List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusOne(characteristicName);
            if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
                return AjaxResult.error("暂时还没有农副产品的信息！");
            }
            return AjaxResult.success(tourismCharacteristics);
        }else if(status == 2){
            List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusTwo(characteristicName);
            if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
                return AjaxResult.error("暂时还没有根雕的信息！");
            }
            return AjaxResult.success(tourismCharacteristics);
        }else if(status == 3){
            List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusThree(characteristicName);
            if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
                return AjaxResult.error("暂时没有非遗产品的信息！");
            }
            return AjaxResult.success(tourismCharacteristics);
        }else if(status == 4){
            List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectByStatusFour(characteristicName);
            if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
                return AjaxResult.error("暂时没有酒水的信息！");
            }
            return AjaxResult.success(tourismCharacteristics);
        }else {
            List<TourismCharacteristic> tourismCharacteristics = tourismCharacteristicMapper.selectAll(characteristicName);
            if(tourismCharacteristics.size() == 0 || tourismCharacteristics == null){
                return AjaxResult.error("暂时还没有商品的信息！");
            }
            return AjaxResult.success(tourismCharacteristics);
        }
    }


}
